Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configure, configure Makevars.in -> Makevars #165

Merged
merged 4 commits into from
Jan 8, 2024

Conversation

mlondschien
Copy link
Owner

No description provided.

@Ilia-Kosenkov
Copy link

I think some one else is missing, unable to cross-compile. Lemme check

@Ilia-Kosenkov
Copy link

Ilia-Kosenkov commented Jan 7, 2024

@eitsupi, hi, we are dealing with a cross-compilation issue. Could you please help us figure out cross-compilation from Max OS x86_64 to aarch64? I used polars-r as an example, but I still do not understand how to build a package without linking to R library, which in this case causes an architecture mismatch (R session links to x86_64 library while cargo artifact is aarch64)

@eitsupi
Copy link

eitsupi commented Jan 7, 2024

I don't know how to cross compile R packages.
Regarding conda-forge, packages like dplyr have binaries for arm64, so why not use them as a reference?

The only thing I know a little about is cross-compilation in Rust. I'm sure you can find a lot of information about it on the internet.

@yutannihilation
Copy link

Okay, so, if even polars is not cross-compile-aware, I guess there's no Rust-powered R package that does it correctly. In my understanding, extendr never aimed at cross-compiling for arm64 macOS, so it's no surprise that this doesn't work. Anyone would be welcomed to explore this frontier. But, IMHO, cross-compiling is a temporary solution until the arm64 macOS runner is generally available, so I'm not sure if it's really worth the effort.

That being said, here's a good news (or bad news) that we might get a reason that forces us to think about cross-compiling seriously.

r-universe-org/help#97 (comment)

@eitsupi
Copy link

eitsupi commented Jan 8, 2024

What is possible with prqlr (and polars) is to cross-compile the Rust library in advance and use that binary when installing the R package to avoid the cargo build when installing the R package.
https://github.com/eitsupi/prqlr/blob/76c68dda761c0b5f5783b03154c20b6127b306b1/configure#L50-L76
https://github.com/eitsupi/prqlr/blob/76c68dda761c0b5f5783b03154c20b6127b306b1/src/Makevars.in#L19-L22
We have never cross-compiled the entire R package.

So if a cross-compilation method has been established for C, it would be possible to build the R package by cross-compiling Rust and C in this way, respectively.

As I mentioned above, some packages such as dplyr are available on arm64 Linux and macOS on conda-forge, so it is not impossible to build R packages using Rust, I think?

@yutannihilation
Copy link

Yeah, I believe it's definitely possible and I bet it's just specifying target correctly.

@eitsupi
Copy link

eitsupi commented Jan 8, 2024

As for Linux, I believe we can build the R package by cross-compiling the Rust library on the host machine and then running arm64 R on Docker with qemu.
But not sure about macOS.

Since cargo-cross seems to support cross-compilation of packages other than Linux, it may be possible to cross-compile R packages in the same way, but I have not tried it.
(Incidentally, since there is no R on the Docker image used by cargo-cross, it cannot be used for Linux as it is.)
https://github.com/cross-rs/cross

@yutannihilation

This comment was marked as off-topic.

@yutannihilation
Copy link

Confirmed that specifying --target makes it possible to cross-compile for arm64 macOS at least on R-universe. I'm not interested in conda so I'd stop here, but hope this helps to some extent.

diff: https://github.com/yutannihilation/string2path/compare/912ae92..9576797
log: https://github.com/r-universe/yutannihilation/actions/runs/7443083907/job/20247512893#step:7:56

@mlondschien
Copy link
Owner Author

I get the same error locally:

    Finished release [optimized] target(s) in 1m 57s
if [ "" != "true" ]; then \
                rm -Rf /Users/mlondschien/code/changeforest/changeforest-r/src/.cargo && \
                rm -Rf ./rust/target/release/build; \
        fi
arm64-apple-darwin20.0.0-clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Users/mlondschien/mambaforge/envs/r-test/lib/R/lib -Wl,-dead_strip_dylibs -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/mlondschien/mambaforge/envs/r-test/lib -L/Users/mlondschien/mambaforge/envs/r-test/lib -o changeforest.dylib entrypoint.o -L./rust/target/release -lchangeforestr -L/Users/mlondschien/mambaforge/envs/r-test/lib/R/lib -lR -Wl,-framework -Wl,CoreFoundation
ld: library not found for -lchangeforestr
arm64-apple-darwin20.0: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [changeforest.dylib] Error 1
ERROR: compilation failed for package ‘changeforest’
* removing ‘/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest’
* restoring previous ‘/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest’

If I replace -lchangeforestr with -lchangeforest in the Makevars, I get

arm64-apple-darwin20.0.0-clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Users/mlondschien/mambaforge/envs/r-test/lib/R/lib -Wl,-dead_strip_dylibs -Wl,-pie -Wl,-headerpad_max_install_names -Wl,-dead_strip_dylibs -Wl,-rpath,/Users/mlondschien/mambaforge/envs/r-test/lib -L/Users/mlondschien/mambaforge/envs/r-test/lib -o changeforest.dylib entrypoint.o -L./rust/target/release -lchangeforest -L/Users/mlondschien/mambaforge/envs/r-test/lib/R/lib -lR -Wl,-framework -Wl,CoreFoundation
ld: warning: -pie being ignored. It is only used when linking a main executable
installing to /Users/mlondschien/mambaforge/envs/r-test/lib/R/library/00LOCK-changeforest-r/00new/changeforest/libs
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘changeforest’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/00LOCK-changeforest-r/00new/changeforest/libs/changeforest.dylib':
  dlopen(/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/00LOCK-changeforest-r/00new/changeforest/libs/changeforest.dylib, 0x0006): symbol not found in flat namespace '_R_init_changeforest_extendr'
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest’
* restoring previous ‘/Users/mlondschien/mambaforge/envs/r-test/lib/R/library/changeforest’

@yutannihilation
Copy link

If you specify --target=aarch64-apple-darwin, LIBDIR should be ./rust/target/aarch64-apple-darwin/release, not ./rust/target/release.

arm64-apple-darwin20.0.0-clang ..snip.. -L./rust/target/release -lchangeforestr ...

@mlondschien mlondschien force-pushed the use-polars-makewin-and-configure branch from 84c3495 to d931494 Compare January 8, 2024 11:34
@mlondschien mlondschien merged commit f2159e9 into main Jan 8, 2024
20 checks passed
@mlondschien mlondschien deleted the use-polars-makewin-and-configure branch January 8, 2024 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants